﻿<%@page import="com.dfhc.ISystemConstant"%>
<%@page import="com.dfhc.rm.user.IUserConstants"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<%@ taglib uri="/dfhc" prefix="dfhc" %>
<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<title>报表模板管理</title>
</head>
<body>

<dfhc:template templateUrl="/pubController/getLayoutTemp/?jspUrl=/temp/huiBodyTemp" >	 
 	<dfhc:region name="searchRegion"> 
	<form name="searchForm" id="searchForm" action="">
	<dfhc:div templateId="h_ui_div_search">
	 	新增日期范围：
	 <dfhc:input templateId="h_ui_date_input" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\\'datemax\\')||\\'%y-%M-%d\\'}' })" id="datemin" name="startCreateTime"/>
	 -
	 <dfhc:input templateId="h_ui_date_input" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\\'datemin\\')}',maxDate:'%y-%M-%d' })" id="datemax" name="endCreateTime"/>
		<dfhc:input templateId="h_ui_search_input" placeholder="输入报表编码，描述或模板文件名" id="" name="searchName"/>
		<dfhc:button templateId="h_ui_search_button" id="" name="" onclick="javascript:_searchData();" />
	</dfhc:div>
	</form>
     </dfhc:region> 
     <dfhc:region name="buttonRegion">
        <dfhc:div templateId="h_ui_div_table_button">
        <dfhc:span templateId="h_ui_button_span">
        <dfhc:button templateId="h_ui_add_button" onclick="_showPage('添加报表模板','${pageContext.request.contextPath }/pubController/openJsp?jspUrl=/qb5activiti/report/reportdef-add','','350')" />
        <dfhc:button templateId="h_ui_update_button" onclick="report_edit()" />
		<dfhc:button templateId="h_ui_delete_button" onclick="report_del()" />
		</dfhc:span>
		<dfhc:span templateId="h_ui_total_record_num_span">${RM_PAGE_VO.recordCount}</dfhc:span>		
	    </dfhc:div>		       
     </dfhc:region> 
    <dfhc:region name="tableRegion">
    	<dfhc:table templateId="table_h_ui" >    	
		<dfhc:thead>
			<dfhc:tr> 
				<dfhc:th width="25">
				   <dfhc:checkbox name="allId" />
				</dfhc:th>	
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >报表编码</dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >描述</dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="90">
				   <dfhc:title templateId="title_h_ui" >报表xml模板</dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="150">
				   <dfhc:title templateId="title_h_ui" >报表二进制模板</dfhc:title>
				</dfhc:th>			
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >创建时间</dfhc:title>
				</dfhc:th>					
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >更新时间</dfhc:title>
				</dfhc:th>
			</dfhc:tr>
    	   </dfhc:thead>			
		</dfhc:table>           
     </dfhc:region>        
     <dfhc:region name="footer"> 
     </dfhc:region> 
</dfhc:template>    

<script type="text/javascript">
var _table;
$(function(){
	_table = $('.table-sort').dataTable({	
	     dom: 'Zlfrtip',	   		
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data);
		       var reportUrl = getReportRootUrl()+"/reportdefine";
		        		       
                $.ajax({  
                        type: "GET",  
                        url: rootPath+"/pubController/proxyGetResetApi?url="+reportUrl,  
                        cache : false,  //禁用缓存  
                        data:param,   
                        dataType: "json",  
                        success: function(result) {  
                                //异常判断与处理  
                                if (result.status=='0') {  
                                    alert(result.message);  
                                    return;  
                                }  
                                //封装返回数据  
                                var returnData = {};  
                                returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                                returnData.recordsTotal = result.recordsTotal;//总记录数  
                                returnData.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                                returnData.data = result.data;  
                                //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                                //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                                callback(returnData);  
                                //更新总记录数
                                $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');
                        },  
                        error: function(XMLHttpRequest, textStatus, errorThrown) {  
                            alert("查询失败");  
                        }  
                    });  
            },  
		"columns": [
		  {
		    "data":"id",
			"render":function(data,type,row,meta){
			   var content='<input type="checkbox" name="allId" value="'+row.id+'"/>';
			   return content; 
			}
		  },
		  {"data":"reportCode"},
		  {"data":"remark"},
		  {"data":"xmlTemplateFileName"},
		  {"data":"binTemplateFileName"},
		  {	   
		    "data":"createTime",
		    "defaultContent":"",
			render:function(data,type,row,meta){
			   var content=formatDate(row.createTime,'yyyy-MM-dd');			 
			   return content; 
			}
		  },
		  {	   
		    "data":"modifyTime",
		    "defaultContent":"",
			render:function(data,type,row,meta){
			   var content=formatDate(row.createTime,'yyyy-MM-dd');			 
			   return content; 
			}
		  }
		  	  
		],
		"columnDefs": [ {"searchable": false,
            "orderable": false,
            "targets": 0 }]  				
	});  	
});
/*拼接参数*/
function splitParameter(data){
	 //var paramJsonStr = formToJson(decodeURIComponent($(searchForm).serialize(),true));
	 var paramJsonStr = $(searchForm).serializeObject();
	 //组装 排序参数
	 if(data.order && data.order.length && data.order[0]){
	  data.sort = data.columns[data.order[0].column].data;
      if(data.sort!='0'){
      	data.dir = data.order[0].dir;
      }else{
        data.sort ='';
        data.dir='';
      }
	}  
	var retVal;
	retVal = $.extend( {}, data,paramJsonStr); 
	return retVal;
}
/修改报表模板*/
function report_edit(){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择修改的记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    //传id，打开修改报表模板页面
    var url = '${pageContext.request.contextPath }/pubController/openJsp?jspUrl=/qb5activiti/report/reportdef-add&id='+ids;
    _showPage('修改报表模板',url,'','350');
}


/*删除报表模板定义*/
function report_del(){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择删除的记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var url;
    //获取根目录
	var fileRootPath = getFileRootPath();
    url = rootPath+"/pubController/proxyPostResetApi?url="+getReportRootUrl()+"/reportdefine/deleteReport&id="+ids+"&rootPath="+fileRootPath;
	layer.confirm('确认要删除吗？',function(index){
		submitAjax(url,'',window.location.href);
	});
}

$.fn.serializeObject=function(){
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
/**
 * 查询用户
 */
function _searchData(){	
	$('.table-sort').DataTable().ajax.reload();
} 
</script> 
</body>
</html>